#ifndef VIEWRESOLVER
#define VIEWRESOLVER

#include <base\vec3f.h>
#include <base\vec2i.h>

#include <app\states\modelInfoState.h>
#include <app\states\viewingParametersState.h>
#include <app\states\terrainTileState.h>
#include <app\states\textureTileState.h>

#include <commands\client\c_request_terrain_tile.h>
#include <commands\client\c_request_texture_tile.h>

#include <render\observers\moveObserver.h>
#include <render\observers\rotateObserver.h>
#include <render\observers\viewChangeObserver.h>
#include <render\levels\level.h>
#include <render\threads\threadBase.h>
#include <render\threads\downloadManager.h>

#include <iostream>
#include <vector>

using namespace std;

class viewResolver : public threadBase, moveObserver, rotateObserver, viewChangeObserver {

  vector<level *> levels;
  vector<vector<boost::shared_ptr<tile> *> > all_loaded_tiles;

  bool            view_change_flag;

  viewingParametersState vp_state;       ///< local copy notified in case of change
  
  boost::mutex    gpu_mutex;
  bool            can_upload_gpu_data;

  downloadManager *downloader;

  //terrainTileState *terrain_tile_state;
  //textureTileState *texture_tile_state;

private:

  void resolveView();

  // the loading thread
  virtual void run();

public:

  virtual void stop();
  virtual void move(const float x, const float y, const float z);
  virtual void rotate(const float x, const float y, const float z);
  virtual void viewChange(const viewingParametersState *vp_state_);

  // render current scene
  void render();

  viewResolver();
  virtual ~viewResolver();

  friend level;
};

#endif